﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace ThreadingSample
{
    public class Card : INotifyPropertyChanged
    {

        //--------------------------------------------------------------------------------------------------------------------------

        private string m_StringURI;

        //--------------------------------------------------------------------------------------------------------------------------

        public Card(string StringURI)
        {
            m_StringURI = StringURI;
        }

        //--------------------------------------------------------------------------------------------------------------------------

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropetyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        //--------------------------------------------------------------------------------------------------------------------------

        private ImageSource m_ImageSource;
        public ImageSource ImageSource
        {
            get
            {
                if (m_ImageSource == null)
                {
                    //IsImageLoading = true;
                    LoadImage();
                    return null;
                }
                return m_ImageSource;
            }
            internal set
            {
                if (value != null)
                {
                    //IsImageLoading = false;
                    m_ImageSource = value;
                    RaisePropetyChanged("ImageSource");
                }
            }
        }

        //--------------------------------------------------------------------------------------------------------------------------

        //public bool IsImageLoading
        //{
        //    get { return m_LoadingImage; }
        //    internal set { m_LoadingImage = value; RaisePropetyChanged("IsImageLoading"); }
        //}

        //--------------------------------------------------------------------------------------------------------------------------

        public Uri URI
        {
            get { return new Uri(m_StringURI); }
        }

        //--------------------------------------------------------------------------------------------------------------------------

        public string Name
        {
            get { return System.IO.Path.GetFileNameWithoutExtension(m_StringURI); }
        }

        //--------------------------------------------------------------------------------------------------------------------------

        public virtual void LoadImage()
        {
            DoLoadImage();
        }

        //--------------------------------------------------------------------------------------------------------------------------

        protected void DoLoadImage()
        {
            ImageSource = new BitmapImage(URI);
        }

        //--------------------------------------------------------------------------------------------------------------------------

    }
}
